<style>
.con {
  /* display: flex;
    justify-content: center;
    align-items: center; */
  margin-top: 50px;
  /* border: 1px solid #ccc; */
}
</style>
<template>
  <div class="con">
    <el-form
      ref="form"
      :model="proNewProcure"
      :rules="rules"
      label-width="150px"
    >
      <el-col :span="8">
        <el-form-item label="货号" prop="productNo">
          <el-input
            v-model="proTemplate.productNo"
            placeholder="请输入货号"
            :disabled="true"
          />
        </el-form-item>
        <!-- <el-form-item label="图片地址" prop="picUrl">
                <template #default="scope">
                    <el-popover effect="light" trigger="hover" placement="right" width="auto">
                        <template #default>
                            <img :src='pjtUrl + proTemplateSecondry.picUrl' style="width: 300px;height: 200px;">
                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                    </template>
                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                    <template #reference>
                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                        <img :src='pjtUrl + proTemplateSecondry.picUrl' style="width: 100px; height: 100px" />
                                                                                                                                                                                                                                                                                                                                                                                                                                            </template>
                                                                                                                                                                                                                                                                                                                                                                                                                                        </el-popover>
                                                                                                                                                                                                                                                                                                                                                                                                                                    </template>
                                                                                                                                                                                                                                                                                                                                                                                                                                </el-form-item> -->
        <!-- //-----------新增或修改方法里上传图片 -->
        <el-form-item label="产品图" prop="picUrl">
          <!-- <el-upload :action="imgUpload.url" :headers="imgUpload.headers" list-type="picture-card" :limit="limit"
                                                                                                                                                                                                :on-exceed="handleExceed" :on-success="handlePictureSuccessPic" :before-upload="beforeAvatarUpload"
                                                                                                                                                                                                :on-preview="handlePictureCardPreview" :file-list="files" :on-change="changeFile1">
                                                                                                                                                                                                <i class="el-icon-plus"></i>
                                                                                                                                                                                            </el-upload>
                                                                                                                                                                                            <el-dialog :visible.sync="dialogVisible">
                                                                                                                                                                                                <img width="100%" v-if="picUrl" :src="picUrl" alt="">
                                                                                                                                                                                            </el-dialog> :on-preview="handlePictureCardPreview" :on-remove="handleRemove" :on-remove="handlePic"-->
          <el-upload
            ref="uploadPic"
            :action="imgUpload.url"
            :headers="imgUpload.headers"
            list-type="picture-card"
            :on-change="changePic"
            :file-list="filePic"
            multiple
            :on-success="uploadPic"
            :on-remove="RemovePic"
          >
            <i class="el-icon-plus"></i>
          </el-upload>
          <div id="preview" @paste="handlePic">
            <span
              ><i class="el-icon-s-opportunity" style="color: #fb894c"></i
              >点击此处 将图片按Ctrl+V 粘贴至此处</span
            >
          </div>
        </el-form-item>
        <el-form-item label="颜色属性" prop="colorProperty">
          <el-input
            v-model="proTemplateSecondry.colorProperty"
            placeholder="请输入颜色属性"
            :disabled="true"
          />
        </el-form-item>
        <el-form-item label="尺寸" prop="proTemplateSizeList">
          <el-select
            v-model="checked"
            placeholder="请选择尺寸"
            clearable
            multiple
            @change="test"
          >
            <el-option
              v-for="dict in dict.type.sys_product_size"
              :key="dict.value"
              :label="dict.label"
              :value="dict.value"
            />
          </el-select>
          <!-- <el-checkbox-group v-model="checked" @change="test">
                    <el-checkbox v-for="item in checkList" :key="item.id" :label="item.id" :disabled="true">{{
                        item.label }}
                        </el-checkbox>
                                                                                                                                                                                                                                                                        </el-checkbox-group> -->

          <!-- <el-checkbox-group v-model="form.proTemplateSizeList" :min="1" :max="6" size="medium">
                                                                                                                                      <el-checkbox v-for="(item, index) in proTemplateSizeListOptions" :key="index" :label="item.value"
                                                                                                                                        :disabled="item.disabled">{{ item.label }}</el-checkbox>
                                                                                                                                      </el-checkbox-group> -->
        </el-form-item>
        <!-- <el-form-item label="logo图片" prop="picUrl">
                <template #default="scope">
                    <el-popover effect="light" trigger="hover" placement="right" width="auto">
                        <template #default>
                            <img :src='pjtUrl + proTemplateSecondry.logoUrl' style="width: 300px;height: 200px;">
                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                            </template>
                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                            <template #reference>
                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                <img :src='pjtUrl + proTemplateSecondry.logoUrl' style="width: 100px; height: 100px" />
                                                                                                                                                                                                                                                                                                                                                                                                                                                                        </template>
                                                                                                                                                                                                                                                                                                                                                                                                                                                                    </el-popover>
                                                                                                                                                                                                                                                                                                                                                                                                                                                                </template>
                                                                                                                                                                                                                                                                                                                                                                                                                                                            </el-form-item> -->
        <!-- //-----------新增或修改方法里上传图片 -->
        <el-form-item label="logo图片" prop="logoUrl">
          <!-- <el-upload :action="imgUpload.url" :headers="imgUpload.headers" list-type="picture-card" :limit="limit"
                                                                                                                                            :on-exceed="handleExceed" :on-success="handlePictureSuccess" :before-upload="beforeAvatarUpload"
                                                                                                                                            :on-preview="handlePictureCardPreview" :file-list="fileList" :on-change="changeFile2">
                                                                                                                                            <i class="el-icon-plus"></i>
                                                                                                                                        </el-upload>
                                                                                                                                        <el-dialog :visible.sync="dialogVisible">
                                                                                                                                            <img width="100%" v-if="imageUrl" :src="imageUrl" alt="">
                                                                                                                                        </el-dialog> -->
          <el-upload
            ref="uploadlogourl"
            :action="imgUpload.url"
            :headers="imgUpload.headers"
            list-type="picture-card"
            :on-change="changelogourl"
            :file-list="filelogourl"
            multiple
            :on-success="uploadlogourl"
            :on-remove="Removelogourl"
          >
            <i class="el-icon-plus"></i>
          </el-upload>
          <div id="preview" @paste="handlelogourl">
            <span
              ><i class="el-icon-s-opportunity" style="color: #fb894c"></i
              >点击此处 将图片按Ctrl+V 粘贴至此处</span
            >
          </div>
        </el-form-item>
        <!-- //-----------新增或修改方法里上传图片 -->
        <el-form-item label="logo位置" prop="logoPosition">
          <el-upload
            ref="uploadlogoFull"
            :action="imgUpload.url"
            :headers="imgUpload.headers"
            list-type="picture-card"
            :on-change="changelogoFull"
            :file-list="filelogoFull"
            multiple
            :on-success="uploadlogoFull"
            :on-remove="RemovelogoFull"
          >
            <i class="el-icon-plus"></i>
          </el-upload>
          <div id="preview" @paste="handlelogoFull">
            <span
              ><i class="el-icon-s-opportunity" style="color: #fb894c"></i
              >点击此处 将图片按Ctrl+V 粘贴至此处</span
            >
          </div>
        </el-form-item>

        <el-form-item label="生产厂家代码" prop="manufacturerCode">
          <!-- <el-input v-model="proTemplate.manufacturerCode" placeholder="请输入生产厂家代码" :disabled="true" /> -->
          <el-select
            v-model="proTemplateSecondry.manufacturerCode"
            placeholder="请选择厂家代码"
            clearable
            filterable
          >
            <el-option
              v-for="dict in dict.type.sys_product_coder"
              :key="dict.value"
              :label="dict.label"
              :value="dict.value"
            />
          </el-select>
        </el-form-item>
        <el-form-item label="下单数量" prop="orderNum">
          <el-input
            v-model="proNewProcure.orderNum"
            placeholder="请输入下单数量"
            style="width: 220px"
          />
        </el-form-item>
        <el-form-item label="确认下单时间" prop="orderTime">
          <el-date-picker
            clearable
            v-model="proNewProcure.orderTime"
            type="date"
            value-format="yyyy-MM-dd"
            placeholder="请选择下单时间"
          >
          </el-date-picker>
        </el-form-item>
      </el-col>
      <el-col :span="2"> <el-form-item></el-form-item></el-col>
      <el-col :span="7">
        <!-- @focus="onFocus" remote
                        :remote-method="getmianliao"-->
        <el-form-item label="主面料名称" prop="designFabricName">
          <el-select
            v-model="proTemplate.designFabricName"
            clearable
            filterable
            placeholder="主面料名称"
            @change="change"
          >
            <el-option
              v-for="(item, index) in mianliao"
              :key="index"
              :label="item"
              :value="item"
            >
            </el-option>
          </el-select>
          <!-- <el-select v-model="proTemplate.designFabricName" placeholder="请选择面料名称" clearable remote
                        :remote-method="getmianliao()" @change="change">
                        <el-option v-for="dict in mianliao" :key="dict" :label="dict" :value="dict" />
                    </el-select> -->
        </el-form-item>
        <el-form-item label="织坯期(天)" prop="procureWeavingPeriod">
          <el-input
            v-model="proTemplate.procureWeavingPeriod"
            placeholder="请输入织坯期"
            style="width: 220px"
          />
        </el-form-item>
        <el-form-item label="染色期(天)" prop="procureStainPeriod">
          <el-input
            v-model="proTemplate.procureStainPeriod"
            placeholder="请输入染色期"
            style="width: 220px"
          />
        </el-form-item>
        <el-form-item label="车间生产周期(天)" prop="workshopCycle">
          <!-- <el-input v-model="proNewProcure.workshopCycle" placeholder="请输入车间生产周期" style="width:220px" /> -->
          <el-select
            v-model="proTemplate.workshopCycle"
            placeholder="请选择车间生产周期"
            clearable
          >
            <el-option
              v-for="dict in dict.type.sys_product_cycle"
              :key="dict.label"
              :label="dict.value"
              :value="dict.value"
            />
          </el-select>
        </el-form-item>
        <el-form-item label="预计出货时间" prop="shippingTime">
          <el-date-picker
            clearable
            v-model="proNewProcure.shippingTime"
            type="date"
            value-format="yyyy-MM-dd"
            placeholder="请选择出货时间"
          >
          </el-date-picker>
          <el-radio-group
            v-model="radio"
            size="small"
            @change="changeTheme"
            fill="#66b1ff"
          >
            <el-radio :label="0">预计</el-radio>
            <el-radio :label="1">确认</el-radio>
            <el-radio :label="2">取消</el-radio>
          </el-radio-group>

          <!-- :label="确认"  :label="预计"  <el-button plain icon="el-icon-edit" size="mini" @click="edit">确认</el-button> -->
          <!-- <template slot-scope="scope">
                        
                                                                                                <el-button plain icon="el-icon-edit" size="mini"
                                                                                                    v-show="scope.row.isShippingTime == '1'">已确认</el-button>
                                                                                            </template> -->
        </el-form-item>

        <el-form-item label="面料成分" prop="fabricComposition">
          <el-input
            v-model="proTemplate.fabricComposition"
            placeholder="请输入面料成分"
            type="textarea"
            :autosize="{ minRows: 3, maxRows: 4 }"
            :style="{ width: '100%' }"
          />
        </el-form-item>
        <el-form-item label="面料检测报告" prop="fabricTestRepor">
          <el-input
            v-model="proTemplate.fabricTestRepor"
            placeholder="面料检测报告"
            type="textarea"
            :autosize="{ minRows: 2, maxRows: 12 }"
            :style="{ width: '100%' }"
          />
        </el-form-item>
        <el-form-item label="请输入备注" prop="procureRemark">
          <!-- @blur="updateData" @keyup.enter.native="enterBlur($event)" -->
          <el-input
            v-model="proNewProcure.procureRemark"
            placeholder="请输入备注"
            type="textarea"
            :autosize="{ minRows: 2, maxRows: 4 }"
            :style="{ width: '100%' }"
          />
        </el-form-item>
        <el-form-item label="成衣检测报告" prop="purchasingReportAttachments">
          <el-input
            v-model="proTemplateSecondry.purchasingReportAttachments"
            placeholder="请输入成衣检测报告"
            type="textarea"
            :autosize="{ minRows: 3, maxRows: 12 }"
            :style="{ width: '100%' }"
          />
        </el-form-item>
        <el-form-item
          label="请选择修改说明备注"
          prop="purchasingAccessoriesMark"
        >
          <!-- <template>
                                                                                                            <el-select v-model="proNewRelation.purchasingAccessoriesMark" @visible-change="editSelect" multiple
                                                                                                            default-first-option placeholder="请选择备注">
                                                                                                                <el-option v-for="item in options" :key="item.value" :label="item.purchasingAccessoriesMark"
                                                                                                                                                                                                                                                                                                                                                                                                                                                                                :value="item.value">
                                                                                                                                                                                                                                                                                                                                                                                                                            </el-option>
                                                                                                                                                                                                                                                                                                                                                                                                                            </el-select>
                                                                                                                                                                                                                                                                                                                                                                                                                        </template> 
                                                                                                                                                                                                                                                                                                                                                                                                                    type="textarea"
                                                                                                                                                                                                                                                                                                                                                                                :autosize="{ minRows: 4, maxRows: 4 }" :style="{ width: '100%' }" 
                                                                                                                                                                                                                                                                                                                                                                                                                    -->

          <el-select
            v-model="proNewRelation.purchasingAccessoriesMark"
            placeholder="请选择辅料备注"
            clearable
            filterable
            remote
            :remote-method="get"
            @change="changeMark"
          >
            <el-option
              v-for="item in optionsMark"
              :key="item.id"
              :label="item.purchasingAccessoriesMark"
              :value="item.purchasingAccessoriesMark"
            />
          </el-select>
        </el-form-item>
        <!--@blur="updateData" @keyup.enter.native="enterBlur($event)"
                     <el-form-item label="辅料修改前图片" prop="purchasingBeforePicurl">
                    <template #default="scope">
                        <el-popover effect="light" trigger="hover" placement="right" width="auto">
                            <template #default>
                                <img :src='pjtUrl + proNewRelation.purchasingBeforePicurl'
                                    style="width: 300px;height: 200px;">
                            </template>
                            <template #reference>
                                <img :src='pjtUrl + proNewRelation.purchasingBeforePicurl'
                                    style="width: 100px; height: 100px" />
                            </template>
                        </el-popover>
                    </template>
                </el-form-item>
                <el-form-item label="辅料修改后图片" prop="purchasingAfterPicurl">
                    <template #default="scope">
                        <el-popover effect="light" trigger="hover" placement="right" width="auto">
                            <template #default>
                                <img :src='pjtUrl + proNewRelation.purchasingAfterPicurl'
                                    style="width: 300px;height: 200px;">
                            </template>
                                                                                                                                                                                                                                                                                                                                                                                                                        <template #reference>
                                                                                                                                                                                                                                                                                                                                                                                                                            <img :src='pjtUrl + proNewRelation.purchasingAfterPicurl'
                                                                                                                                                                                                                                                                                                                                                                                                                            style="width: 100px; height: 100px" />
                                                                                                                                                                                                                                                                                                                                                                                                                    </template>
                                                                                                                                                                                                                                                                                                                                                                                                                </el-popover>
                                                                                                                                                                                                                                                                                                                                                                                                            </template>
                                                                                                                                                                                                                                                                                                                                                                                                        </el-form-item> -->
        <!-- //-----------新增或修改方法里上传图片 -->
        <el-form-item label="辅料修改前图片" prop="purchasingBeforePicurl">
          <el-upload
            :action="imgUpload.url"
            :headers="imgUpload.headers"
            list-type="picture-card"
            :limit="limit"
            :on-exceed="handleExceed"
            :on-success="handlePictureSuccessBefore"
            :before-upload="beforeAvatarUpload"
            :on-preview="handlePictureCardPreview"
            :file-list="fileBefore"
            :disabled="true"
          >
            <!-- <i class="el-icon-plus"></i> -->
          </el-upload>
          <el-dialog :visible.sync="dialogVisible">
            <img width="100%" v-if="imageUrl" :src="imageUrl" alt="" />
          </el-dialog>
        </el-form-item>
        <!-- //-----------新增或修改方法里上传图片 -->
        <el-form-item label="辅料修改后图片" prop="purchasingAfterPicurl">
          <el-upload
            :action="imgUpload.url"
            :headers="imgUpload.headers"
            list-type="picture-card"
            :limit="limit"
            :on-exceed="handleExceed"
            :on-success="handlePictureSuccessAfter"
            :before-upload="beforeAvatarUpload"
            :on-preview="handlePictureCardPreview"
            :file-list="fileAfter"
            :disabled="true"
          >
            <!-- <i class="el-icon-plus"></i> -->
          </el-upload>
          <el-dialog :visible.sync="dialogVisible">
            <img width="100%" v-if="imageUrl" :src="imageUrl" alt="" />
          </el-dialog>
        </el-form-item>
        <div class="footer" style="width: 400px; text-align: center">
          <el-button type="primary" @click="submitForm">确 定</el-button>
          <el-button @click="cancel" style="margin-left: 30px"
            >返回上一级</el-button
          >
        </div>
      </el-col>
    </el-form>
  </div>
</template>
<script>
import {
  listCycle,
  getCycle,
  delCycle,
  addCycle,
  updateCycle,
  selectProFabricCycleByName,
} from "@/api/data/cycle";
import {
  listFabric,
  getInfoByName,
  selectFabricNameList,
} from "@/api/data/Fabric";
import {
  listHistory,
  getHistory,
  delHistory,
  addHistory,
  updateHistory,
} from "@/api/product/history";
import {
  listRelation,
  getRelation,
  delRelation,
  addRelation,
  updateRelation,
} from "@/api/product/relation";
import {
  listPurchase,
  getPurchase,
  delPurchase,
  addPurchase,
  updatePurchase,
} from "@/api/edit/purchase";
//--------导入token
import { getToken } from "@/utils/auth";
export default {
  name: "Purchase",
  dicts: [
    "sys_product_qudao",
    "sys_product_size",
    "sys_product_design",
    "sys_product_scene",
    "sys_product_coder",
    "sys_product_yf",
    "sys_product_cycle",
  ],
  data() {
    return {
      //面料名称
      mianliao: [],
      //是否确认收货
      radio: 0,

      //修改说明备注
      optionsMark: [],

      purchasingBeforePicurl: "",
      purchasingAfterPicurl: "",
      fileBefore: [{ url: "" }],
      fileAfter: [{ url: "" }],
      proNewRelation: {},
      customerPicture: "",

      //图片地址-搁置
      // picUrl: '',

      pjtUrl: process.env.VUE_APP_BASE_API,
      // 图片数量限制
      limit: 2,
      innerVisible: false,
      //页面上存的暂时图片地址List
      // files: [{ url: "" }],
      picurl: "",
      filePic: [],
      upload_Pic: [], //提交的图片数组
      //页面上存的暂时logo图片地址List
      // fileList: [{ url: "" }],
      //logo相对路径
      logoUrl: "",
      filelogourl: [],
      upload_logourl: [], //提交的图片数组
      //页面上存的暂时logo图片地址List
      // fileLi: [{ url: "" }],
      logoFull: "",
      filelogoFull: [],
      //图片地址
      imageUrl: "",
      dialogVisible: false,
      imgUpload: {
        // 设置上传的请求头部
        headers: {
          Authorization: "Bearer " + getToken(),
        },
        // 图片上传的方法地址:
        url: process.env.VUE_APP_BASE_API + "/common/upload",
      },
      checked: [],
      checkList: [
        { id: 1, label: "XS" },
        { id: 2, label: "S" },
        { id: 3, label: "M" },
        { id: 4, label: "L" },
        { id: 5, label: "XL" },
        { id: 6, label: "XXL" },
        { id: 7, label: "均码" },
        // { id: 0002, label: '汽车' },
        // { id: 0002, label: '火车' },
      ],
      // pjtUrl: process.env.VUE_APP_BASE_API,
      proTemplateSecondry: {}, //二级
      proTemplate: {}, //一级
      // 表单参数
      form: {
        // proNewProcure:
      },
      proNewProcure: {},
      // 表单校验
      rules: {},
    };
  },

  created() {
    // this.getList();
    this.handleUpdate();
  },
  methods: {
    changeTheme(val) {
      // console.log(val);
      this.form.proNewProcure.isShippingTime = val;
    },

    changeMark(val) {
      console.log(val);
      // if (val == this.proNewRelation.purchasingAccessoriesMark) {
      //     this.$modal.msgWarning('已选择该项！如需显示图片：先选择其他项，再选择回来')
      //     return

      // , productNo: this.proTemplate.productNo
      listHistory({
        purchasingAccessoriesMark: val,
        productNo: this.proTemplate.productNo,
      }).then((response) => {
        let m = [];
        m = response.rows;
        console.log(JSON.stringify(m));
        if (response.rows.length == 1) {
          this.fileAfter = [
            {
              url:
                process.env.VUE_APP_BASE_API +
                response.rows[0].purchasingAfterPicurl,
            },
          ]; //logo图片加的是这一行
          this.fileBefore = [
            {
              url:
                process.env.VUE_APP_BASE_API +
                response.rows[0].purchasingBeforePicurl,
            },
          ]; //logo图片加的是这一行
          this.purchasingBeforePicurl = response.rows[0].purchasingBeforePicurl;
          this.purchasingAfterPicurl = response.rows[0].purchasingAfterPicurl;
          console.log(JSON.stringify(this.purchasingBeforePicurl));
          this.form.proNewRelation.purchasingAfterPicurl =
            this.purchasingAfterPicurl;
          this.form.proNewRelation.purchasingBeforePicurl =
            this.purchasingBeforePicurl;
        }
      });
    },
    updateData(event) {
      //更新操作
      console.log("updated", this.proNewRelation.purchasingAccessoriesMark);
      listHistory({
        purchasingAccessoriesMark:
          this.proNewRelation.purchasingAccessoriesMark,
      }).then((response) => {
        let m = [];
        m = response.rows;
        console.log(JSON.stringify(m));
        // this.fileAfter = [
        //     { url: process.env.VUE_APP_BASE_API + response.rows[0].purchasingAfterPicurl }]//logo图片加的是这一行
        // this.fileBefore = [
        //     { url: process.env.VUE_APP_BASE_API + response.rows[0].purchasingBeforePicurl }]//logo图片加的是这一行
        // this.purchasingBeforePicurl = response.rows[0].purchasingBeforePicurl
        // this.purchasingAfterPicurl = response.rows[0].purchasingAfterPicurl
        // console.log(JSON.stringify(this.purchasingBeforePicurl));
        // this.form.proNewRelation.purchasingAfterPicurl = this.purchasingAfterPicurl
        // this.form.proNewRelation.purchasingBeforePicurl = this.purchasingBeforePicurl
        // this.$router.go(0)
        // this.proTemplate.designFabricFunction = response.data.designFabricFunction
        // this.proTemplate.designSpecialPresentation = response.data.designSpecialPresentation
        // this.proTemplate.designExerciseIntensity = response.data.designExerciseIntensity
        // this.proTemplate.designFitnessLevels = response.data.designFitnessLevels
        // this.proTemplate.designSomatosensory = response.data.designSomatosensory
        // this.proTemplate.designSoftness = response.data.designSoftness
        // this.proTemplate.designFabricThickness = response.data.designFabricThickness
        // this.proTemplate.designBreathability = response.data.designBreathability
      });
    },
    //回车失去焦点
    enterBlur(event) {
      event.target.blur();
      // console.log(event.target.blur());
    },
    editSelect(e) {
      console.log(e);
    },
    get() {
      console.log(this.proTemplate.productNo);
      listHistory({ productNo: this.proTemplate.productNo }).then((res) => {
        this.optionsMark = res.rows;
        console.log(JSON.stringify(res.rows));
      });
    },
    test(val) {
      console.log(val);
      console.log(this.checked);
      let label = [];
      // this.checked = val;
      // this.checkList.forEach(item => {
      //   this.checked.forEach(j => {
      //     if (item.id == j) {
      //       // console.log(item.label);
      //       label.push({ size: item.label })
      //     }

      //   })

      // })
      this.checked.forEach((item) => {
        label.push({ size: item });
      });
      if (label == null) {
        this.$modal.msgError("请选择至少一个尺寸！");
        return;
      }
      console.log(JSON.stringify(label));
      this.form.proNewVO.proNewSizeList = label;

      this.$forceUpdate();
    },
    // test() {
    //     this.$modal.msgError("禁止修改尺寸");

    // },
    /** 查询产品采购信息列表 */
    getList() {
      this.loading = true;
      listPurchase(this.queryParams).then((response) => {
        this.purchaseList = response.rows;
        this.total = response.total;
        this.loading = false;
      });
    },
    // 取消按钮
    cancel() {
      this.$router.go(-1);
      return;
      this.open = false;
      this.reset();
    },
    // 表单重置
    reset() {
      this.fileBefore = undefined;
      this.fileAfter = undefined;
      // this.files = undefined;//加的是这一行
      // this.fileList = undefined;//加的是这一行
      this.fileLi = undefined; //加的是这一行
      this.proNewProcure = {
        id: null,
        proNewId: null,
        orderNum: null,
        orderTime: null,
        fabricCycle: null,
        workshopCycle: null,
        shippingTime: null,
        fabricComposition: null,
        isDelete: null,
        createBy: null,
        createTime: null,
        updateBy: null,
        updateTime: null,
      };
      this.resetForm("form");
    },
    //面料名称
    getmianliao() {
      // this.loading = true;
      selectFabricNameList().then((response) => {
        console.log(JSON.stringify(response));
        this.mianliao = response;
        // console.log(JSON.stringify(this.FabricList));
        // this.total = response.total;
        // this.loading = false;
      });
    },
    /** 修改按钮操作 */
    handleUpdate(row) {
      this.reset();
      // const id = row.id || this.ids
      const id = this.$route.query.id;
      if (!id) {
        this.$modal.msgError("请点击左侧菜单-上新管理进入");
        return;
      }
      getRelation(id).then((response) => {
        this.proNewRelation = response.data.proNewRelation;
        if (response.data.proNewProcure) {
          this.proNewProcure = response.data.proNewProcure;
        }

        //二级
        this.proTemplateSecondry = response.data.proTemplateSecondry;
        //一级
        this.proTemplate = response.data.proTemplate;
        this.form = response.data;
        console.log(JSON.stringify(this.form));

        this.open = true;
        this.title = "修改产品采购信息";
        //
        this.radio = this.proNewProcure.isShippingTime;
        //logo位置
        this.customerPicture = this.proTemplate.logoPosition;
        //图片回显
        this.picurl = response.data.proTemplateSecondry.picUrl;
        this.logoUrl = response.data.proTemplateSecondry.logoUrl;
        this.logoFull = response.data.proTemplate.logoPosition;

        this.form.proNewRelation.purchasingAccessoriesMark =
          response.data.proNewRelation.purchasingAccessoriesMark;
        // this.fileAfter = [
        //     { url: process.env.VUE_APP_BASE_API + response.data.proNewRelation.purchasingAfterPicurl }]//logo图片加的是这一行
        // this.fileBefore = [
        //     { url: process.env.VUE_APP_BASE_API + response.data.proNewRelation.purchasingBeforePicurl }]//logo图片加的是这一行
        this.filelogoFull = response.data.proTemplate.logoPosition
          ? [
              {
                url:
                  process.env.VUE_APP_BASE_API +
                  response.data.proTemplate.logoPosition,
              },
            ]
          : []; //logo图片加的是这一行
        this.filePic = response.data.proTemplateSecondry.picUrl
          ? [
              {
                url:
                  process.env.VUE_APP_BASE_API +
                  response.data.proTemplateSecondry.picUrl,
              },
            ]
          : []; //图片加的是这一行
        this.filelogourl = response.data.proTemplateSecondry.logoUrl
          ? [
              {
                url:
                  process.env.VUE_APP_BASE_API +
                  response.data.proTemplateSecondry.logoUrl,
              },
            ]
          : []; //logo图片加的是这一行
        //尺寸回显

        if (
          response.data.proNewVO.proNewSizeList &&
          response.data.proNewVO.proNewSizeList.length > 0
        ) {
          let val = response.data.proNewVO.proNewSizeList.map((item) => {
            return item.size;
          });
          console.log(val);
          this.checked = val;
          // console.log(JSON.stringify(val));
          // let m = []
          // for (let i = 0; i < val.length; i++) {
          //     // const element = array[i];
          //     this.checkList.forEach(item => {
          //         if (val[i] == item.label) {
          //             m.push(item.id)
          //         }
          //     })

          // }

          // console.log(JSON.stringify(m));
          // this.checked = m
          // this.$set(this.form, 'checked', m)
        }
        console.log(response.data.proNewRelation.purchasingAccessoriesMark);
        if (response.data.proNewRelation.purchasingAccessoriesMark) {
          console.log(1);
          this.changeMark(
            response.data.proNewRelation.purchasingAccessoriesMark
          );
        }
        this.get();
        //面料名称
        this.getmianliao();
        // this.change(this.proTemplate.designFabricName)
      });
    },
    change(val) {
      console.log(val);
      // console.log(JSON.stringify(this.proTemplate.designPropertyCategory));
      getInfoByName(val).then((response) => {
        let m = [];
        m = response.data;
        console.log(JSON.stringify(m));
        this.proTemplate.designFlexibility = response.data.designFlexibility;
        this.proTemplate.designFabricFunction =
          response.data.designFabricFunction;
        this.proTemplate.designSpecialPresentation =
          response.data.designSpecialPresentation;
        this.proTemplate.designExerciseIntensity =
          response.data.designExerciseIntensity;
        this.proTemplate.designFitnessLevels =
          response.data.designFitnessLevels;
        this.proTemplate.designSomatosensory =
          response.data.designSomatosensory;
        this.proTemplate.designSoftness = response.data.designSoftness;
        this.proTemplate.designFabricThickness =
          response.data.designFabricThickness;
        this.proTemplate.designBreathability =
          response.data.designBreathability;
        this.proTemplate.fabricTestRepor = response.data.fabricTestRepor;
        // this.proTemplate.
        this.proTemplate.copywritingFamily = response.data.copywritingFamily;
        this.proTemplate.copywritingFabricName =
          response.data.copywritingFabricName;

        this.proTemplate.procureWeavingPeriod =
          response.data.procureWeavingPeriod;
        this.proTemplate.procureStainPeriod = response.data.procureStainPeriod;
      });
      // selectProFabricCycleByName(val).then(response => {
      //     let m = []
      //     m = response.data;
      //     console.log(JSON.stringify(m));

      // this.proTemplate.copywritingFamily = response.data.copywritingFamily
      // this.proTemplate.copywritingFabricName = response.data.copywritingFabricName
      // this.proTemplate.designFabricFunction = response.data.designFabricFunction
      // this.proTemplate.designSpecialPresentation = response.data.designSpecialPresentation
      // this.proTemplate.designExerciseIntensity = response.data.designExerciseIntensity
      // this.proTemplate.designFitnessLevels = response.data.designFitnessLevels
      // this.proTemplate.designSomatosensory = response.data.designSomatosensory
      // this.proTemplate.designSoftness = response.data.designSoftness
      // this.proTemplate.designFabricThickness = response.data.designFabricThickness
      // this.proTemplate.designBreathability = response.data.designBreathability

      // });
    },
    // getchange(val) {
    //     console.log(val);
    //     // console.log(JSON.stringify(this.proTemplate.designPropertyCategory));
    //     selectProFabricCycleByName(val).then(response => {
    //         let m = []
    //         m = response.data;
    //         console.log(JSON.stringify(m));
    //         this.proTemplateSecondry.procureWeavingPeriod = response.data.procureWeavingPeriod
    //         this.proTemplateSecondry.procureStainPeriod = response.data.procureStainPeriod
    //         // this.proTemplate.copywritingFamily = response.data.copywritingFamily
    //         // this.proTemplate.copywritingFabricName = response.data.copywritingFabricName
    //         // this.proTemplate.designFabricFunction = response.data.designFabricFunction
    //         // this.proTemplate.designSpecialPresentation = response.data.designSpecialPresentation
    //         // this.proTemplate.designExerciseIntensity = response.data.designExerciseIntensity
    //         // this.proTemplate.designFitnessLevels = response.data.designFitnessLevels
    //         // this.proTemplate.designSomatosensory = response.data.designSomatosensory
    //         // this.proTemplate.designSoftness = response.data.designSoftness
    //         // this.proTemplate.designFabricThickness = response.data.designFabricThickness
    //         // this.proTemplate.designBreathability = response.data.designBreathability

    //     });
    // },
    /** 提交按钮 */
    submitForm() {
      // if (this.form.proNewVO.proTemplateSizeList == null) {
      //     this.$modal.msgError('请选择至少一个尺寸！')
      //     return
      // }
      console.log(JSON.stringify(this.purchasingAfterPicurl));
      this.form.proNewRelation.purchasingAfterPicurl =
        this.purchasingAfterPicurl;
      this.form.proNewRelation.purchasingBeforePicurl =
        this.purchasingBeforePicurl;
      this.form.proTemplate.logoPosition = this.logoFull; //logo位置
      this.form.proTemplateSecondry.picUrl = this.picurl;
      this.form.proTemplateSecondry.logoUrl = this.logoUrl; // 注：重要(用于添加到数据库)，
      this.form.proNewProcure = this.proNewProcure;
      console.log(JSON.stringify(this.form));
      updateRelation(this.form).then((response) => {
        this.$modal.msgSuccess("修改成功");
        this.open = false;
        console.log(JSON.stringify(response));
        this.handleUpdate();
      });
      this.$refs["form"].validate((valid) => {
        if (valid) {
          if (this.form.id != null) {
          } else {
            // addPurchase(this.form).then(response => {
            //     this.$modal.msgSuccess("新增成功");
            //     this.open = false;
            //     this.getList();
            // });
          }
        }
      });
    },
    //图片上传前的相关判断
    beforeAvatarUpload(file) {
      const isJPG = file.type === "image/jpeg" || file.type == "image/png";
      const isLt2M = file.size / 1024 / 1024 < 5;
      if (!isJPG) {
        this.$message.error("上传头像图片只能是 JPG/PNG 格式!");
      }
      if (!isLt2M) {
        this.$message.error("上传头像图片大小不能超过 5MB!");
      }
      return isJPG && isLt2M;
    },
    //图片预览
    handlePictureCardPreview(file) {
      // this.picUrl = file.url
      this.imageUrl = file.url;
      this.customerPicture = file.url;
      this.purchasingBeforePicurl = file.url;
      this.purchasingAfterPicurl = file.url;
      this.dialogVisible = true;
    },
    //图片上传成功后的回调
    handlePictureSuccessAfter(res, file) {
      //设置图片访问路径 （url 后台传过来的的上传地址）
      // this.customerPicture = file.response.url;
      // const url = file.response.fileName;
      this.purchasingAfterPicurl = file.response.fileName;
    },
    //图片上传成功后的回调
    handlePictureSuccessBefore(res, file) {
      //设置图片访问路径 （url 后台传过来的的上传地址）
      // this.customerPicture = file.response.url;
      // const url = file.response.fileName;
      this.purchasingBeforePicurl = file.response.fileName;
      // console.log(JSON.stringify(this.customerPicture));
    },
    //图片上传成功后的回调
    handlePictureSuccessCustomer(res, file) {
      //设置图片访问路径 （url 后台传过来的的上传地址）
      // this.customerPicture = file.response.url;
      // const url = file.response.fileName;
      this.customerPicture = file.response.fileName;
      console.log(JSON.stringify(this.customerPicture));
    },
    handlePictureSuccessPic(res, file) {
      //设置图片访问路径 （url 后台传过来的的上传地址）
      // this.picUrl = file.response.url;
      // const url = file.response.fileName;
      this.picurl = file.response.fileName;
    },
    //图片上传成功后的回调
    handlePictureSuccess(res, file) {
      //设置图片访问路径 （url 后台传过来的的上传地址）
      this.imageUrl = file.response.url;
      // const url = file.response.fileName;
      this.logoUrl = file.response.fileName;
      // console.log(JSON.stringify(url));
    },

    // 文件个数超出
    handleExceed() {
      this.$modal.msgError(`上传链接LOGO图片数量不能超过 ${this.limit} 个!`);
    },
    changeFile1(file, fileList) {
      if (fileList.length > 1) {
        this.files = fileList.slice(-1);

        // this.fileList = [fileList[fileList.length - 1]]//这一步，是 展示最后一次选择文件
      }
      // this.fileSpecial = fileList;
    },
    changeFile2(file, fileList) {
      if (fileList.length > 1) {
        this.fileList = fileList.slice(-1);

        // this.fileList = [fileList[fileList.length - 1]]//这一步，是 展示最后一次选择文件
      }
      // this.fileSpecial = fileList;
    },
    changeFile3(file, fileList) {
      if (fileList.length > 1) {
        this.fileLi = fileList.slice(-1);

        // this.fileList = [fileList[fileList.length - 1]]//这一步，是 展示最后一次选择文件
      }
      // this.fileSpecial = fileList;
    },
    handlePic(event) {
      const items = (event.clipboardData || window.clipboardData).items;
      let file = null;
      if (!items || items.length === 0) {
        this.$message.error("当前浏览器不支持本地");
        return;
      }
      // 搜索剪切板items
      for (let i = 0; i < items.length; i++) {
        if (items[i].type.indexOf("image") !== -1) {
          file = items[i].getAsFile();
          break;
        }
      }
      if (!file) {
        this.$message.error("粘贴内容非图片");
        return;
      }
      if (this.filePic.length >= this.limit) {
        this.$message.error(`上传文件数量不能超过 ${this.limit} 个!`); // 图片数量超出
        return;
      }
      this.$refs.uploadPic.handleStart(file); // 将粘贴过来的图片加入预上传队列
      this.$refs.uploadPic.submit(); // 提交图片上传队列
    },
    //上传
    changePic(file, fileList) {
      // this.fileList = fileList
      console.log("成功", file, fileList, this.filePic);
      console.log(JSON.stringify(file));
      console.log(JSON.stringify(fileList));
      if (fileList.length > 1) {
        this.filePic = fileList.slice(-1);
      }
    },
    RemovePic() {
      this.picurl = "";
    },

    uploadPic(res, file, fileList) {
      console.log(JSON.stringify(file.response.fileName));
      this.picurl = file.response.fileName;
    },

    //logo图片
    handlelogourl(event) {
      const items = (event.clipboardData || window.clipboardData).items;
      let file = null;
      if (!items || items.length === 0) {
        this.$message.error("当前浏览器不支持本地");
        return;
      }
      // 搜索剪切板items
      for (let i = 0; i < items.length; i++) {
        if (items[i].type.indexOf("image") !== -1) {
          file = items[i].getAsFile();
          break;
        }
      }
      if (!file) {
        this.$message.error("粘贴内容非图片");
        return;
      }
      if (this.filelogourl.length >= this.limit) {
        this.$message.error(`上传文件数量不能超过 ${this.limit} 个!`); // 图片数量超出
        return;
      }
      this.$refs.uploadlogourl.handleStart(file); // 将粘贴过来的图片加入预上传队列
      this.$refs.uploadlogourl.submit(); // 提交图片上传队列
    },
    //上传
    changelogourl(file, fileList) {
      // this.fileList = fileList
      console.log("成功", file, fileList);
      console.log(JSON.stringify(file));
      console.log(JSON.stringify(fileList));
      if (fileList.length > 1) {
        this.filelogourl = fileList.slice(-1);
      }
    },
    Removelogourl() {
      this.logoUrl = "";
    },

    uploadlogourl(res, file, fileList) {
      console.log(JSON.stringify(file.response.fileName));
      this.logoUrl = file.response.fileName;
    },

    //logo位置
    handlelogoFull(event) {
      const items = (event.clipboardData || window.clipboardData).items;
      let file = null;
      if (!items || items.length === 0) {
        this.$message.error("当前浏览器不支持本地");
        return;
      }
      // 搜索剪切板items
      for (let i = 0; i < items.length; i++) {
        if (items[i].type.indexOf("image") !== -1) {
          file = items[i].getAsFile();
          break;
        }
      }
      if (!file) {
        this.$message.error("粘贴内容非图片");
        return;
      }
      if (this.filelogoFull.length >= this.limit) {
        this.$message.error(`上传文件数量不能超过 ${this.limit} 个!`); // 图片数量超出
        return;
      }
      this.$refs.uploadlogoFull.handleStart(file); // 将粘贴过来的图片加入预上传队列
      this.$refs.uploadlogoFull.submit(); // 提交图片上传队列
    },
    //上传
    changelogoFull(file, fileList) {
      // this.fileList = fileList
      console.log("成功", file, fileList);
      console.log(JSON.stringify(file));
      console.log(JSON.stringify(fileList));
      if (fileList.length > 1) {
        this.filelogoFull = fileList.slice(-1);
      }
    },
    RemovelogoFull() {
      this.logoFull = "";
    },
    uploadlogoFull(res, file, fileList) {
      console.log(JSON.stringify(file.response.fileName));
      this.logoFull = file.response.fileName;
    },
  },
};
</script>

<style lang="scss" scoped>
::deep.el-upload--picture-card,
::deep.el-upload-list__item {
  width: 100px;

  height: 100px;

  line-height: 110px;
}
</style>